const cors = require("koa2-cors");
const { TOKEN_ISSUE_KEY } = require("../../sys_config");

module.exports = {
  name: "cors",

  core: cors({
    origin() {
      return "*";
    },
    maxAge: 5, //指定本次预检请求的有效期，单位为秒。
    credentials: true, //是否允许发送Cookie
    allowMethods: ["GET", "POST", "PUT", "DELETE", "OPTIONS"], //设置所允许的HTTP请求方法'
    allowHeaders: ["Content-Type", "Authorization", "Accept", TOKEN_ISSUE_KEY], //设置服务器支持的所有头信息字段
    exposeHeaders: [
      "WWW-Authenticate",
      "Server-Authorization",
      TOKEN_ISSUE_KEY,
    ], //设置获取其他自定义字段
  }),
};
